package ar.fiuba.tp7552.buildadmin.webactions;

import ar.fiuba.tp7552.buildadmin.model.BaseEntity;

import com.opensymphony.xwork2.validator.ValidationException;
import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;

public class EntityRequiredField extends FieldValidatorSupport {

	public void validate(Object object) throws ValidationException {
	 
		String fieldName = getFieldName();
		Object value = this.getFieldValue(fieldName, object);

		if (value != null && !(value instanceof BaseEntity)) {
			return;
		} else {
			BaseEntity entity = (BaseEntity) value;
			if (entity == null || entity.getId() == null)
				addFieldError(fieldName, object);
		}
	}
}